﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;

namespace MongoServices
{
	/// <summary>
	/// The base &quot;Read Only&quot; service.
	/// </summary>
	/// <typeparam name="T">The MongoServices model to be used by this service.</typeparam>
	public abstract class ReadOnlyService<T> : MongoServicesService<T>, IReadOnlyService<T>
		where T : MongoServicesModel
	{
		#region Protected Properties
		/// <summary>
		/// Gets the <see cref="IReadOnlyRepository&lt;T&gt;"/> that was passed into the constructor.
		/// </summary>
		protected IReadOnlyRepository<T> ReadOnlyRepository { get; private set; }
		#endregion

		#region Public Constructors
		/// <summary>
		/// Constructs a ReadOnlyService based on the <c>readOnlyRepository</c> parameter.
		/// </summary>
		/// <param name="readOnlyRepository">The <see cref="IReadOnlyRepository&lt;T&gt;"/> to be used with this service.</param>
		public ReadOnlyService(IReadOnlyRepository<T> readOnlyRepository)
			: base(readOnlyRepository)
		{
			ReadOnlyRepository = readOnlyRepository;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Gets a collection of the <see cref="MongoServicesModel"/>s from the <see cref="IReadOnlyRepository&lt;T&gt;"/>.
		/// </summary>
		/// <returns>An enumerable list of the models.</returns>
		public IEnumerable<T> GetAll()
		{
			return ReadOnlyRepository.GetAll();
		}

		/// <summary>
		/// Gets one <see cref="MongoServicesModel"/> from the <see cref="IReadOnlyRepository&lt;T&gt;"/>.
		/// </summary>
		/// <param name="id">The &quot;Id&quot; of the <see cref="MongoServicesModel"/> to be retrieved.</param>
		/// <returns>The selected <see cref="MongoServicesModel"/>.</returns>
		public T GetById(ObjectId id)
		{
			return ReadOnlyRepository.GetById(id);
		}
		#endregion
	}
}
